using UnityEngine;

namespace AutoChess
{
    class ActorTransform : ActorCmpt
    {
        public GameObject ActorGO { get; set; }

        public Transform GoTrans { get; set; }

        public Vector3 Position
        {
            get { return GoTrans.position;}
            set { GoTrans.position = value; }
        }

        public Vector3 Forward
        {
            get { return GoTrans.forward; }
            set { GoTrans.forward = value; }
        }

        public Quaternion Rotation
        {
            get { return GoTrans.rotation; }
            set { GoTrans.rotation = value; }
        }

        public Vector3 LocalScale
        {
            get
            {
                if (GoTrans != null)
                {
                    return GoTrans.localScale;
                }
                return Vector3.one;
            }
        }

        protected override void Awake()
        {
           ActorGO = new GameObject();
           var trans = ActorGO.transform;
           GoTrans = trans;
           OwnActor.SetActorGoParent();

           var localPos = Vector3.zero;
           CreateStaticDummy(trans, localPos, DummyPoint.DM_S_ROOT);
           CreateStaticDummy(trans, localPos, DummyPoint.DM_S_BREAST);
           CreateStaticDummy(trans, localPos, DummyPoint.DM_S_HEAD);
        }

        private void CreateStaticDummy(Transform rootTrans, Vector3 localPos, DummyPoint dummyType)
        {
            string dummyName = AvatarDefine.GetDummyPointName(dummyType);
            if(string.IsNullOrEmpty(dummyName))
                return;
            
            GameObject dummyGo = new GameObject(dummyName);
            dummyGo.transform.parent = rootTrans;
            dummyGo.transform.localRotation = Quaternion.identity;
            dummyGo.transform.localPosition = localPos;
        }
    }
}